import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, BUSINESS_DATA, REGISTERED_CAPITAL, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY } from '@/utils/tableColumn';
import {setHrefUrlTool} from "@/utils";

export function useTable(data) {
  const totalSize = computed(() => {
    return data?.value?.total ?? 0;
  });
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      field: 'noticeDate',
      title: '披露日期',
      align: 'center',
      sortable: true,
      width: 110,
      sortBy: 'noticeDate'
    },
    {
      width: 280,
      field: 'attachments',
      title: '信息来源',
      slots: {
        default: ({ row }) => {
          return (
            <div>
              <a title={row.catalogueName} onClick={() => setHrefUrlTool(row.fileType, row.fileUrl)}>
                {row.catalogueName || '查看'}
              </a>
              <br />
            </div>
          );
        }
      }
    },
    {
      field: 'technologyTypeCode',
      title: '技术阶段',
      align: 'center',
      sortable: true,
      width: 110,
      sortBy: 'technologyTypeCode'
    },
    {
      field: 'technologyField',
      title: '技术领域',
      align: 'center',
      sortable: true,
      width: 200,
      sortBy: 'technologyField'
    },
    {
      field: 'technology',
      title: '技术装备名称',
      width: 110,
      sortBy: 'technology'
    },
    { ...PROVINCE },
    { ...CITY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    totalSize,
    columns
  };
}
